Friday, 26 January 2018

Try GridBag Layout in java

Try GridBag Layout in java
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.Border;
public class TryGridBagLayout {
  static JFrame aWindow = new JFrame("This is a Gridbag Layout");
  public static void main(String[] args) {
    aWindow.setBounds(30, 30, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    aWindow.getContentPane().setLayout(gridbag);
    constraints.weightx = constraints.weighty = 10.0;
    constraints.fill = constraints.BOTH;
    addButton(" Press ", constraints, gridbag);
    constraints.gridwidth = constraints.REMAINDER;
    addButton("GO", constraints, gridbag);
    aWindow.setVisible(true);
  }
  static void addButton(String label, GridBagConstraints constraints, GridBagLayout layout) {
    Border edge = BorderFactory.createRaisedBevelBorder();
    JButton button = new JButton(label);
    button.setBorder(edge);
    layout.setConstraints(button, constraints);
    aWindow.getContentPane().add(button);
  }
}

Monday, 21 August 2017

Auto clock Project

#include<graphics.h>
#include<stdio.h>
void clock(void);
void clock1(void);
void main()
{
int a,x,y,d,m;
d=DETECT;
initgraph(&d,&m,"C:\\TC\\BGI");
cleardevice();
setcolor(4);
clock();
for(x=303,y=150;x<=353;x=x+10)/*FROM 12 TO 1*/
    {
    setcolor(4);
    line(303,210,x,y+5);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=353,y=155;x<=403,y<=180;x+=10,y+=6)/*FROM 1 TO 2*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=403,y=180;y<=250;y+=10)/*FROM 2 TO 4*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=403,y=250;x>=350,y<=270;x-=10,y+=4)/*FROM 4 TO 5*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=350,y=270;x>=250;x-=10)/*FROM 5 TO 7*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=250,y=270;x>=200,y>=250;x-=8,y-=4)/*FROM 7 TO 8*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=200,y=250;y>=170;y-=8)/*FROM 8 TO 10*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=200,y=170;x<=250,y>=150;x+=10,y-=2)/*FROM 10 TO 11*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
cleardevice();
clock1();
getch();
closegraph();
}

void clock(void)
{
setbkcolor(14);
setcolor(2);
outtextxy(350,150,"1");
outtextxy(250,150,"11");
outtextxy(300,150,"12");

outtextxy(400,170,"2");
outtextxy(400,210,"3");
outtextxy(400,250,"4");

outtextxy(350,270,"5");
outtextxy(300,270,"6");
outtextxy(250,270,"7");

outtextxy(200,250,"8");
outtextxy(200,210,"9");
outtextxy(200,170,"10");

setcolor(1);
line(180,130,420,130);
line(180,290,420,290);
line(180,130,180,290);
line(420,130,420,290);
circle(303,210,7);
setcolor(6);
setlinestyle(0,0,3);
line(303,210,303,250);
setcolor(11);
setlinestyle(0,5,2);
line(303,210,303,155);
}


void clock1(void)
{
setbkcolor(14);
setcolor(2);
outtextxy(350,150,"1");
outtextxy(250,150,"11");
outtextxy(300,150,"12");

outtextxy(400,170,"2");
outtextxy(400,210,"3");
outtextxy(400,250,"4");

outtextxy(350,270,"5");
outtextxy(300,270,"6");
outtextxy(250,270,"7");

outtextxy(200,250,"8");
outtextxy(200,210,"9");
outtextxy(200,170,"10");

setcolor(1);
line(180,130,420,130);
line(180,290,420,290);
line(180,130,180,290);
line(420,130,420,290);
circle(303,210,7);
setcolor(6);
setlinestyle(0,0,3);
line(303,210,303,250);
setcolor(11);
setlinestyle(0,5,2);
line(303,210,313,155);
setcolor(4);
line(303,210,303,155);
getch();
}

DataBase project of class file 3

DataBase project of class file 3
void inputs(int c[],int so[],int ss[],int sss[],int k)
    {
    int i;
    printf("Enter Roll No.=");
        scanf("%d",&c[k]);
    for(i=0;i<k;i++)
        if(c[k]==c[i])
            {
            printf("Roll No. of Two Students cannot be Same.\n");
            printf("Enter Roll No. Again=");
                scanf("%d",&c[k]);
            }   
    printf("Enter MARKS of SUBJECT 1=");
        scanf("%d",&so[k]);
    printf("Enter MARKS of SUBJECT 2=");
        scanf("%d",&ss[k]);
    printf("Enter MARKS of SUBJECT 3=");
        scanf("%d",&sss[k]);
    }


void mao(int m[],int so[],int ss[],int sss[],int k)
    {
    m[k]=so[k]+ss[k]+sss[k];
    }


void age(float p[],int m[],int k)
    {
    p[k]=m[k]/3.0;
    }

   
void gra(int gd[],float p[],int k)
    {
    if(p[k]>=80)
        gd[k]=1;
    else if(p[k]>=70 && p[k]<80)
        gd[k]=2;
    else if(p[k]>=60 && p[k]<70)
        gd[k]=3;
    else if(p[k]>=50 && p[k]<60)
        gd[k]=4;
    else
        gd[k]=5;
    }


double cavg(int m[],int l)
    {
    int i,sum=0;
    double ca;
    for(i=0;i<l;i++)
        sum=sum+m[i];
    ca=sum/l;
    return ca;
    }


void first_last(int m[],int c[],int l)
    {
    int i,max=m[0],max_index=0,min=m[0],min_index=0;
    clrscr();
    for(i=1;i<l;i++)
        {
        if(max<m[i])
            {
            max=m[i];
            max_index=i;
            }
        else if(min>m[i])
            {
            min=m[i];
            min_index=i;
            }
        }
    printf("Roll Number of TOPPER Student is %d",c[max_index]);
    printf("\nRoll Number of NULL Student is %d",c[min_index]);
    }


void sortA_mao(int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int e[],int l)
    {
    int i,j,large,l_index;
    for(i=0;i<l-1;i++)
        {
        large=m[i];
        l_index=i;
        for(j=i+1;j<l;j++)
            {
            if(large<m[j])
                {
                large=m[j];
                l_index=j;
                }
            }
        m[l_index]=m[i];
        m[i]=large;
       
       
        e[i]=c[i];
        c[i]=c[l_index];
        c[l_index]=e[i];           
            e[i]=so[i];
            so[i]=so[l_index];
            so[l_index]=e[i];
        e[i]=ss[i];
        ss[i]=ss[l_index];
        ss[l_index]=e[i];
            e[i]=sss[i];
            sss[i]=sss[l_index];
            sss[l_index]=e[i];
        e[i]=p[i];
        p[i]=p[l_index];
        p[l_index]=e[i];
            e[i]=gd[i];
            gd[i]=gd[l_index];
            gd[l_index]=e[i];
        }
    }


void sortD_mao(int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int e[],int l)
    {
    int i,j,small,s_index;
    for(i=0;i<l-1;i++)
        {
        small=m[i];
        s_index=i;
        for(j=i+1;j<l;j++)
            {
            if(small>m[j])
                {
                small=m[j];
                s_index=j;
                }
            }
        m[s_index]=m[i];
        m[i]=small;
       
       
        e[i]=c[i];
        c[i]=c[s_index];
        c[s_index]=e[i];           
            e[i]=so[i];
            so[i]=so[s_index];
            so[s_index]=e[i];
        e[i]=ss[i];
        ss[i]=ss[s_index];
        ss[s_index]=e[i];
            e[i]=sss[i];
            sss[i]=sss[s_index];
            sss[s_index]=e[i];
        e[i]=p[i];
        p[i]=p[s_index];
        p[s_index]=e[i];
            e[i]=gd[i];
            gd[i]=gd[s_index];
            gd[s_index]=e[i];
        }
    }


void fetch(int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int el,int l)
    {
    int i,a,loc=-1;
    char g;
    clrscr();
    printf("R.No.\tSUB 1\tSUB 2\tSUB 3\tT.MARKS\t%AGE\tGRADE");
    for(i=0;i<l;i++)
        {
        switch(gd[i])
            {
            case 1:
                g='A';
                break;
            case 2:
                g='B';
                break;
            case 3:
                g='C';
                break;
            case 4:
                g='D';
                break;
            case 5:
                g='F';
                break;
            }
        if(el==c[i])
            {
            loc=i;
            break;
            }
        }   
        if(loc==-1)
            printf("\nSORRY! \x1 RECORD OF \"%d\" DOES NOT EXIST.",el);
        else
            {
            printf("\n%d\t%d\t%d\t%d\t%d\t%0.2f\t%c",c[loc],so[loc],ss[loc],sss[loc],m[loc],p[loc],g);
            }
    }


void display(int s[],int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int l,double ca)
    {
    int i;
    char g;
    clrscr();
    printf("S.No.\tR.No.\tSUB 1\tSUB 2\tSUB 3\tT.MARKS\t%AGE\tGRADE\n");
    for(i=0;i<l;i++)
        {
        s[i]=i+1;
        switch(gd[i])
            {
            case 1:
                g='A';
                break;
            case 2:
                g='B';
                break;
            case 3:
                g='C';
                break;
            case 4:
                g='D';
                break;
            case 5:
                g='F';
                break;
            }
        printf("%d\t%d\t%d\t%d\t%d\t%d\t%0.2f\t%c\n",s[i],c[i],so[i],ss[i],sss[i],m[i],p[i],g);
        }
    printf("\nCLASS AVERAGE is=%0.2f",ca);
    }


void S_display(int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int l,double ca)
    {
    int i;
    char g;
    clrscr();
    printf("R.No.\tSUB 1\tSUB 2\tSUB 3\tT.MARKS\t%AGE\tGRADE\n");
    for(i=0;i<l;i++)
        {
        switch(gd[i])
            {
            case 1:
                g='A';
                break;
            case 2:
                g='B';
                break;
            case 3:
                g='C';
                break;
            case 4:
                g='D';
                break;
            case 5:
                g='F';
                break;
            }
        printf("%d\t%d\t%d\t%d\t%d\t%0.2f\t%c\n",c[i],so[i],ss[i],sss[i],m[i],p[i],g);
        }
    printf("\nCLASS AVERAGE is=%0.2f",ca);
    }

DataBase project of class .H file

#include<stdio.h>
#include<database.h>
#include<graphics.h>
#define s 60
int sn[s],cn[s],s1[s],s2[s],s3[s],mo[s],gr[s],ex[s];
float page[s];
double cav;
void main()
{
int m,d,m1,j,t,e;
char ch;
d=DETECT;
initgraph(&d,&m,"C:\\TC\\BGI");
cleardevice();
setcolor(10);
setbkcolor(8);
printf("Enter NUMBER of Students in the CLASS:");
    scanf("%d",&m1);
for(j=0;j<m1;j++)
    {
    inputs(cn,s1,s2,s3,j);
        mao(mo,s1,s2,s3,j);
    age(page,mo,j);
        gra(gr,page,j);
    }
cav=cavg(mo,m1);
display(sn,cn,s1,s2,s3,mo,page,gr,m1,cav);
printf("\n\nDo You Want to See who is TOPPER & who is NULL ?(Y/N)");
    ch=getch();
if(ch=='y' || ch=='Y')
    first_last(mo,cn,m1);
else
    printf("\nOK");
printf("\n\nDo You Want to Sort the Table w.r.t T.MARKS ?(Y/N)");
    ch=getch();
if(ch=='y' || ch=='Y')
    {
    printf("\nPress 'a' for ASCENDING ORDER & 'd' for DESCENDING ORDER");
        ch=getch();
    if(ch=='a' || ch=='A')
        {
        sortA_mao(cn,s1,s2,s3,mo,page,gr,ex,m1);
        S_display(cn,s1,s2,s3,mo,page,gr,m1,cav);
        }
    else
        {
        sortD_mao(cn,s1,s2,s3,mo,page,gr,ex,m1);
        S_display(cn,s1,s2,s3,mo,page,gr,m1,cav);
        }
    }
else
    printf("\nOK");
printf("\nDo You Want to See the Records of Particular Students ?(Y/N)");
    ch=getch();
if(ch=='y' || ch=='Y')
    {
    clrscr();
    printf("How Many RECORDS You want to See ?");
        scanf("%d",&t);
    for(j=1;j<=t;j++)
        {
        printf("\nEnter Class No. of the Student Whose Record You Want to Fetch:");
        scanf("%d",&e);
        fetch(cn,s1,s2,s3,mo,page,gr,e,m1);
        }
    }
else
    printf("\nOK");
getch();
closegraph();
}

Sunday, 20 August 2017

pateint.java java examples

package ACP.Patient;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.io.*;

class Patient implements Serializable
{
    private String patientName;
    private String fatherName;
    private String diseaseCategory;
    private String patientCNIC;
    private String doctorName;
    private String prescription;
    private String diseaseHistory;
    private Date   dateOfBirth;
    private int    patientID;
   
    private static int nextID = 0;
//////////-----------------------------Constructor-----------------------------//////////
    Patient()
    {
        this.setPatientInfo();
    }
//////////-----------------------Method setPatientInfo------------------------//////////
    void setPatientInfo()
    {
        String[] diseaseCategories = {"", "Heart", "ENT", "Diabetic", "Brain", "Orthopedic", "General"};
        String[] doctors       = {"", "Dr. Faridullah Khan(Cardiologist)", "Dr. Muhammad Tariq(ENT Specialist)", "Dr. Muhammad Faisal(Diabetes Specialist)", "Dr. Ejaz Ahmed(Neurologist)", "Dr. Ali Akhtar(Orthopedic Surgeon)", "Dr. Rauf Niazi(General Surgeon)"};
        Date currentDate        = new Date();
        DateFormat df           = new SimpleDateFormat("dd/MM/yyyy");
        String tempPrescription       = null;
              //////////////////////////////////////////////////////////////////////////
        this.patientName = JOptionPane.showInputDialog("Enter Patient's Name:");
        while(this.patientName.length()== 0)
            this.patientName = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's Name:");
              //////////////////////////////////////////////////////////////////////////
        this.fatherName = JOptionPane.showInputDialog("Enter Father's Name:");
        while(this.fatherName.length() == 0)
            this.fatherName = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Father's Name:");
              //////////////////////////////////////////////////////////////////////////
        String dOB = JOptionPane.showInputDialog(null, "Enter Patient's Date of Birth:", "dd/MM/yyyy");
        while(true)
        {
            try
            {
                this.dateOfBirth = df.parse(dOB);
                break;
            }
            catch (ParseException e)
            {
                dOB = JOptionPane.showInputDialog(null, "Invalid Input. Enter Again\n\nEnter Patient's Date of Birth:", "dd/MM/yyyy");
            }
        }
              //////////////////////////////////////////////////////////////////////////
        this.patientCNIC = JOptionPane.showInputDialog(null, "Enter Patient's CNIC:", "xxxxx-xxxxxxx-x");
        while(this.patientCNIC.length() == 0 || this.patientCNIC.equals("xxxxx-xxxxxxx-x"))
            this.patientCNIC = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's CNIC:", "xxxxx-xxxxxxx-x");
              //////////////////////////////////////////////////////////////////////////
        this.diseaseCategory = (String) JOptionPane.showInputDialog(null, "Select Patient's Disease Category:", null, JOptionPane.QUESTION_MESSAGE, null, diseaseCategories, diseaseCategories[0]);
        while(this.diseaseCategory.equals(diseaseCategories[0]))
            this.diseaseCategory = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Patient's Disease Category:", null, JOptionPane.ERROR_MESSAGE, null, diseaseCategories, diseaseCategories[0]);
              //////////////////////////////////////////////////////////////////////////
        this.doctorName = (String) JOptionPane.showInputDialog(null, "Select Doctor's Name:", null, JOptionPane.QUESTION_MESSAGE, null, doctors, doctors[0]);
        while(this.doctorName.equals(doctors[0]))
            this.doctorName    = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Doctor's Name:", null, JOptionPane.ERROR_MESSAGE, null, doctors, doctors[0]);
          //////////////////////////////////////////////////////////////////////////
        tempPrescription = JOptionPane.showInputDialog("Enter Prescription:");
        while(tempPrescription.length() == 0)
            tempPrescription = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Prescription:");
        this.prescription   = df.format(currentDate) + "\t" + tempPrescription;
              //////////////////////////////////////////////////////////////////////////
        this.diseaseHistory = df.format(currentDate) + "\t" + this.doctorName + "\t" + tempPrescription;
              //////////////////////////////////////////////////////////////////////////
        if(nextID != 0)
            this.patientID = nextID++;
        else
        {
            nextID         = 9001;
            this.patientID = nextID++;
        }
              //////////////////////////////////////////////////////////////////////////
        JOptionPane.showMessageDialog(null, new JTextArea("Patient ID:\t" + this.patientID + "\nName:\t" + this.patientName + "\nFather Name:\t" + this.fatherName + "\nDate of Birth:\t" + df.format(this.dateOfBirth) + "\nPatient CNIC:\t" + this.patientCNIC + "\nCategory:\t" + this.diseaseCategory + "\nDoctor Name:\t" + this.doctorName + "\nPrescription:\t" + this.prescription + "\nHistory:\t" + this.diseaseHistory), "Patient Added", JOptionPane.INFORMATION_MESSAGE);
    }
//////////----------------------Method updatePatientInfo----------------------//////////
    void updatePatientInfo(Patient[] p, int arraySearchSize)
    {
        String[] doctors = {"", "Dr. Faridullah Khan(Cardiologist)", "Dr. Muhammad Tariq(ENT Specialist)", "Dr. Muhammad Faisal(Diabetes Specialist)", "Dr. Ejaz Ahmed(Neurologist)", "Dr. Ali Akhtar(Orthopedic Surgeon)", "Dr. Rauf Niazi(General Surgeon)"};
        String input     = JOptionPane.showInputDialog("Enter Patient's ID(a number) Whose Information You Want to Update:");
        while(input.length() == 0)
            input    = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's ID(a number) Whose Information You Want to Update:");
       
        int iDtoSearch;
        while(true)
        {
            try
            {
                iDtoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's ID(a number) Whose Information You Want to Update:");
            }
        }
       
        int foundAtIndex = searchIDs_Index(p, arraySearchSize, iDtoSearch);
        if(foundAtIndex == -1)
            JOptionPane.showMessageDialog(null, "No Patient Found with ID '" + iDtoSearch + "'", "Invalid ID", JOptionPane.ERROR_MESSAGE);
        else
        {
            input = (String) JOptionPane.showInputDialog(null, "Select Doctor's Name:", null, JOptionPane.QUESTION_MESSAGE, null, doctors, doctors[0]);
            while(input.length() == 0)
                input = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Doctor's Name:", null, JOptionPane.QUESTION_MESSAGE, null, doctors, doctors[0]);
            p[foundAtIndex].doctorName = input;
            showPatientInfo(p, foundAtIndex);
        }
    }
//////////--------------Method updatePrescriptionDiseaseHistory--------------//////////
    void updatePrescriptionDiseaseHistory(Patient[] p, int arraySearchSize)
    {
        Date currentDate = new Date();
        DateFormat df    = new SimpleDateFormat("dd/MM/yyyy");
        String input     = JOptionPane.showInputDialog("Enter Patient's ID(a number) Whose Prescription You Want to Update:");
        while(input.length() == 0)
            input    = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's ID(a number) Whose Prescription You Want to Update:");
       
        int iDtoSearch;
        while(true)
        {
            try
            {
                iDtoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's ID(a number) Whose Prescription You Want to Update:");
            }
        }
        int foundAtIndex = searchIDs_Index(p, arraySearchSize, iDtoSearch);
        String newPrescription;
        if(foundAtIndex == -1)
            JOptionPane.showMessageDialog(null, "No Patient Found with ID '" + iDtoSearch + "'", "Invalid ID", JOptionPane.ERROR_MESSAGE);
        else
        {
            newPrescription = JOptionPane.showInputDialog("Enter New Prescription:");
            while(newPrescription.length() == 0)
                newPrescription = (String) JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter New Prescription:");
            p[foundAtIndex].prescription   = p[foundAtIndex].prescription + "\n\t" + df.format(currentDate) + "\t" + newPrescription;
            p[foundAtIndex].diseaseHistory = p[foundAtIndex].diseaseHistory + "\n\t" + df.format(currentDate) + "\t" + p[foundAtIndex].doctorName + "\t" + newPrescription;
             showPatientInfo(p, foundAtIndex);
        }
    }
//////////---------------------Method deletePatientInfo----------------------//////////
    int deletePatientInfo(Patient[] p, int arraySearchSize)
    {
        String input  = JOptionPane.showInputDialog("Enter Patient's ID(a number) Whose Record You Want to Delete:");
        while(input.length() == 0)
            input = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's ID(a number) Whose Record You Want to Delete:");
       
        int iDtoSearch;
        while(true)
        {
            try
            {
                iDtoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's ID(a number) Whose Record You Want to Delete:");
            }
        }
        int foundAtIndex = searchIDs_Index(p, arraySearchSize, iDtoSearch);
        if(foundAtIndex == -1)
            JOptionPane.showMessageDialog(null, "No Patient Found with ID '" + iDtoSearch + "'", "Invalid ID", JOptionPane.ERROR_MESSAGE);
        else
            for(int j = foundAtIndex; j < arraySearchSize; j++)
            {
                if(j == arraySearchSize - 1)
                {
                    JOptionPane.showMessageDialog(null, "Record of Patient ID " + iDtoSearch + " is Deleted", "Record Deleted", JOptionPane.INFORMATION_MESSAGE);
                    p[j] = null;
                    return (--arraySearchSize);
                }
                else
                    p[j] = p[j+1];
            }
        return arraySearchSize;
    }
//////////---------------------Method searchView_patientID--------------------//////////
    void searchView_patientID(Patient[] p, int arraySearchSize)
    {
        String input  = JOptionPane.showInputDialog("Enter Patient's ID(a number) Whose Record You Want to Search:");
        while(input.length() == 0)
            input = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's ID(a number) Whose Record You Want to Search:");
       
        int iDtoSearch;
        while(true)
        {
            try
            {
                iDtoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's ID(a number) Whose Record You Want to Search:");
            }
        }
        int foundAtIndex = searchIDs_Index(p, arraySearchSize, iDtoSearch);
        if(foundAtIndex == -1)
            JOptionPane.showMessageDialog(null, "No Patient Found with ID '" + iDtoSearch + "'", "Invalid ID", JOptionPane.ERROR_MESSAGE);
        else
            showPatientInfo(p, foundAtIndex);
    }
//////////--------------------Method searchView_patientName------------------//////////
    void searchView_patientName(Patient[] p, int arraySearchSize)
    {
        DateFormat df  = new SimpleDateFormat("dd/MM/yyyy");
        int totalFound = 0;
        String name    = JOptionPane.showInputDialog("Enter Patient's Name Whose Record You Want to Search:");
        while(name.length() == 0)
            name   = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's Name Whose Record You Want to Search:");
        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize && totalFound == 0)
                JOptionPane.showMessageDialog(null, "No Patient Found with Name '" + name + "'", "Record Not Found", JOptionPane.ERROR_MESSAGE);
            else if(i == arraySearchSize)
                break;
            else if(p[i].patientName.equals(name))
            {
                showPatientInfo(p, i);
                totalFound++;
            }
        }
    }
//////////-------------------Method searchView_patientAge--------------------//////////
    void searchView_patientAge(Patient[] p, int arraySearchSize)
    {
        Date currentDate = new Date();
        int totalFound   = 0;
        String input     = JOptionPane.showInputDialog("Enter Patient's Age(a number) Whose Record You Want to Search:");
        while(input.length() == 0)
            input    = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's Age(a number) Whose Record You Want to Search:");
       
        int AgetoSearch;
        while(true)
        {
            try
            {
                AgetoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's Age(a number) Whose Record You Want to Search:");
            }
        }

        int age;
        int curMonth;
        int birthMonth;
        int curDate;
        int birthDate;

        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize && totalFound == 0)
                JOptionPane.showMessageDialog(null, "No Patient Found with Age '" + AgetoSearch + "'", "Record Not Found", JOptionPane.ERROR_MESSAGE);
            else if(i == arraySearchSize)
                break;
            else
            {
                age       = currentDate.getYear() - p[i].dateOfBirth.getYear();
               
                curMonth   = currentDate.getMonth();
                birthMonth = p[i].dateOfBirth.getMonth();
                curDate       = currentDate.getDate();
                birthDate  = p[i].dateOfBirth.getDate();

                if(curMonth < birthMonth || (curMonth == birthMonth && curDate < birthDate))
                    age--;

                if(AgetoSearch == age)
                {
                    showPatientInfo(p, i);
                    totalFound++;
                }
            }
        }
    }
//////////----------------Method searchView_diseaseCategory------------------//////////
    void searchView_diseaseCategory(Patient[] p, int arraySearchSize)
    {
        String[] diseaseCategories = {"", "Heart", "ENT", "Diabetic", "Brain", "Orthopedic", "General"};
        int totalFound               = 0;
        String categoryToSearch    = (String) JOptionPane.showInputDialog(null, "Select Patient's Disease Category Whose Record You Want to Search:", null, JOptionPane.QUESTION_MESSAGE, null, diseaseCategories, diseaseCategories[0]);
        while(categoryToSearch.equals(diseaseCategories[0]))
            categoryToSearch   = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Patient's Disease Category Whose Record You Want to Search:", null, JOptionPane.ERROR_MESSAGE, null, diseaseCategories, diseaseCategories[0]);
       
        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize && totalFound == 0)
                JOptionPane.showMessageDialog(null, "No Patient Found in '" + categoryToSearch + "' Category", "Record Not Found", JOptionPane.ERROR_MESSAGE);
            else if(i == arraySearchSize)
                break;
            else if(p[i].diseaseCategory.equals(categoryToSearch))
            {
                showPatientInfo(p, i);
                totalFound++;           
            }
        }
    }
//////////-----------------Method searchView_doctorName---------------------//////////
    void searchView_doctorName(Patient[] p, int arraySearchSize)
    {
        String[] doctors = {"", "Dr. Faridullah Khan(Cardiologist)", "Dr. Muhammad Tariq(ENT Specialist)", "Dr. Muhammad Faisal(Diabetes Specialist)", "Dr. Ejaz Ahmed(Neurologist)", "Dr. Ali Akhtar(Orthopedic Surgeon)", "Dr. Rauf Niazi(General Surgeon)"};
        int totalFound   = 0;
        String docName     = (String) JOptionPane.showInputDialog(null, "Select Patient's Doctor Name Whose Record You Want to Search:", null, JOptionPane.QUESTION_MESSAGE, null, doctors, doctors[0]);
        while(docName.equals(doctors[0]))
            docName     = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Patient's Doctor Name Whose Record You Want to Search:", null, JOptionPane.ERROR_MESSAGE, null, doctors, doctors[0]);
       
        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize && totalFound == 0)
                JOptionPane.showMessageDialog(null, "No Patient is Treated by '" + docName + "'", "Record Not Found", JOptionPane.ERROR_MESSAGE);
            else if(i == arraySearchSize)
                break;
            else if(p[i].doctorName.equals(docName))
            {
                showPatientInfo(p, i);
                totalFound++;           
            }
        }
    }
      //_____________________________________________________________
    private int searchIDs_Index(Patient[] p, int arraySearchSize, int iDtoSearch)
    {
        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize)
                return -1;
            else if(p[i].patientID == iDtoSearch)
                return i;
        }
        return -1;
    }
      //_____________________________________________________________
    private void showPatientInfo(Patient[] p, int indexToShow)
    {
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        JOptionPane.showMessageDialog(null, new JTextArea("Patient ID:\t" + p[indexToShow].patientID + "\nName:\t" + p[indexToShow].patientName + "\nFather Name:\t" + p[indexToShow].fatherName + "\nDate of Birth:\t" + df.format(p[indexToShow].dateOfBirth) + "\nPatient CNIC:\t" + p[indexToShow].patientCNIC + "\nCategory:\t" + p[indexToShow].diseaseCategory + "\nDoctor Name:\t" + p[indexToShow].doctorName + "\nPrescription:\t" + p[indexToShow].prescription + "\nHistory:\t" + p[indexToShow].diseaseHistory), "Patient Information", JOptionPane.INFORMATION_MESSAGE);
    }
      //_____________________________________________________________
    static void readNextID()
    {
        String iDFileName = "ACP\\NextID.txt";
        try
        {
            DataInputStream dIS = new DataInputStream(new FileInputStream(iDFileName));
            Patient.nextID        = (int) dIS.readInt();
            dIS.close();   
        }
        catch(FileNotFoundException fNFE){}
        catch(IOException iOE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Reading NextId", JOptionPane.ERROR_MESSAGE);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Reading NextId", JOptionPane.ERROR_MESSAGE);
        }
    }
      //_____________________________________________________________
    static void writeNextID()
    {
        String iDFileName = "ACP\\NextID.txt";
        try
        {
            DataOutputStream dOS = new DataOutputStream(new FileOutputStream(iDFileName));
            dOS.writeInt(Patient.nextID);
            dOS.close();
        }
        catch(IOException iOE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Writing NextId", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Writing NextID", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }   
    }
}

client.java examples of java

package ACP.Patient;

import javax.swing.JOptionPane;
import java.io.*;
//////////////////////////////////////////////////////
class Client
{
    public static void main(String[] fileName)
    {
        final int ARRAY_SIZE    = 50;
        Patient []patient    = new Patient[ARRAY_SIZE];
        int numPatients        = 0;
        String[] choices    = {"", "Add New Patient Record", "Update Patient Information", "Update Prescription & Disease History", "Delete Patient Record", "Search & View Patient Record By Patient ID", "Search & View Patient Record By Patient Name", "Search & View Patient Record By Patient Age", "Search & View Patient Record By Disease category", "Search & View Patient Record By Doctor Name", "Exit"};
        String[] Continue    = {"", "Yes", "No"};
        ObjectOutputStream oOS    = null;
        ObjectInputStream  oIS    = null;
    //////////////////////////////////////////////////////
        String choice        = null;
        String cont        = null;
        int i            = 0;                   
    /////////////////////////////////////////////////////
        if(fileName.length == 0)
        {
            JOptionPane.showMessageDialog(null, "File Name Not Sent From Command Line\nExecute Again With File Name", "Error", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
    ////////////////////////////////////////////////////
        try
        {
            Patient temp = null;
            oIS         = new ObjectInputStream(new FileInputStream(fileName[0]));
            for(i = 0; i < ARRAY_SIZE; i++)
            {
                temp = (Patient) oIS.readObject();
                if(temp != null)
                {
                    patient[i] = temp;
                    numPatients++;
                }
            }
            oIS.close();
        }
        catch(ClassNotFoundException cNFE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + cNFE, "Class Not Found Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        catch(FileNotFoundException fNFE){}
        catch(EOFException eOFE){}
        catch(IOException iOE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }

        Patient.readNextID();
    ///////////////////////////////////////////////////
        do
        {
            choice = (String) JOptionPane.showInputDialog(null, "What You Want To Do ?", "Main Menu", JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]);
            while(choice.equals(choices[0]))
                choice = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nWhat You Want To Do ?", "Main Menu", JOptionPane.ERROR_MESSAGE, null, choices, choices[0]);
       
            if(choice.equals(choices[1]))
            {
                if(numPatients < 0 || numPatients >= ARRAY_SIZE)
                    JOptionPane.showMessageDialog(null, "No Space for New patients :(", "Database Full", JOptionPane.WARNING_MESSAGE);
                else
                {
                    patient[numPatients] = new Patient();
                    numPatients++;
                }               
            }
            else if(choice.equals(choices[2]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].updatePatientInfo(patient, numPatients);
            }   
            else if(choice.equals(choices[3]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].updatePrescriptionDiseaseHistory(patient, numPatients);
            }
            else if(choice.equals(choices[4]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    numPatients = patient[0].deletePatientInfo(patient, numPatients);
            }
            else if(choice.equals(choices[5]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientID(patient, numPatients);
            }
            else if(choice.equals(choices[6]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientName(patient, numPatients);
            }
            else if(choice.equals(choices[7]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientAge(patient, numPatients);
            }
            else if(choice.equals(choices[8]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_diseaseCategory(patient, numPatients);
            }
            else if(choice.equals(choices[9]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_doctorName(patient, numPatients);
            }
            else if(choice.equals(choices[10]))
            {
                JOptionPane.showMessageDialog(null, "Good Bye", "Exiting", JOptionPane.PLAIN_MESSAGE);
                               
                if(numPatients > 0)
                {
                    try                       
                    {
                        oOS = new ObjectOutputStream(new FileOutputStream(fileName[0]));
                        for(i = 0; i < ARRAY_SIZE; i++)
                            oOS.writeObject(patient[i]);
                        oOS.close();
                    }
                    catch(IOException iOE)
                    {
                        JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
                    }
                    catch(Exception e)
                    {
                        JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
                    }

                    Patient.writeNextID();
                }
                System.exit(0);
            }
            cont = (String) JOptionPane.showInputDialog(null, "Want to go back to Main Menu ?", "Continue or Exit", JOptionPane.QUESTION_MESSAGE, null, Continue, Continue[0]);
            while(cont.equals(Continue[0]))
                cont = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nWant to go back to Main Menu ?", "Continue or Exit", JOptionPane.ERROR_MESSAGE, null, Continue, Continue[0]);
        }
        while(cont.equals(Continue[1]));
    ///////////////////////////////////////////////////
        JOptionPane.showMessageDialog(null, "Good Bye", "Exiting", JOptionPane.PLAIN_MESSAGE);
       
        if(numPatients > 0)
        {
            try                       
            {
                oOS = new ObjectOutputStream(new FileOutputStream(fileName[0]));
                for(i = 0; i < ARRAY_SIZE; i++)
                    oOS.writeObject(patient[i]);
                oOS.close();
            }
            catch(IOException iOE)
            {
                JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
            }
            catch(Exception e)
            {
                JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
            }
        }

        Patient.writeNextID();
    ///////////////////////////////////////////////////
    }
}

OS example my shell



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define delim " \t"
#define MAX 100
///////////////// Functions to be Used /////////////////
void get_command();
void parse_command();
void chDir();
char check_for_ampersand();
void spawn_new_process(int signal);
void run_in_background();
///////////////// Variables to be Used /////////////////
char str[MAX];
char *token[MAX/2], *token2[MAX/2];
int pid, died, status;

void main()
{
       printf("Initializing New Shell...\n");
       while(1)
       {
              printf("My Shell ~ $ ");
              get_command();
              parse_command();
              if(strcmp(token[0], "exit") == 0)
                     exit(0);
              else if(strcmp(token[0], "cd") == 0)
                     chDir();
              else
                     switch(check_for_ampersand())
                     {
                           case '&':
                                  spawn_new_process(1);
                                  break;
                           default:
                                  spawn_new_process(0);
                                  break;
                     }
       }
}
///////////////// Get Command from User ////////////////
void get_command()
{
       int i = 0;
       while((i < MAX) && ((str[i] = getchar()) != '\n'))
              i++;
//If Input Extends MAX, the Additional Arguments are Cut
       if(i == MAX)
              str[MAX-1] = '\0';
       else
              str[i] = '\0';
}


///////// Parse Command to Get Different Tokens ////////
void parse_command()
{
       int i = 0;
       token[i] = strtok(str, delim);
       while(token[i] != NULL)
       {
              i++;
              token[i] = strtok(NULL, delim);
       }
}
///////// Change the Current Working Directory /////////
void chDir()
{
       int rv;
       if(token[1] != NULL)
              rv = chdir(token[1]);
       if(rv != 0)
              printf("Error in Changing Directory...\n");
       else
              printf("Current Directory %s\n", token[1]);
}
///////// Check If the Input has '&' Sign in it ////////
char check_for_ampersand()
{
       int i;
       for (i = 0; token[i] != '\0'; i++)
       {
           if (strcmp(token[i], "&") == 0)
                     return token[i][0];
       }
       return '\0';
}
//// Create a New Process Using fork() and execvp() ////
void spawn_new_process(int signal)
{
       switch(pid = fork())
       {
              case -1:
                     // Something did not work....
                     printf("Something went wrong. Unable to create child :(\n");
                     exit(-1);
              case 0:
                     // If Input Contains a '&' Sign, then Run the Processes in Parallel
                     if(signal == 1)
                           run_in_background();
                     else if(signal == 0)
                     {
                           execvp(token[0], token);
                           printf("Command %s not found\n", token[0]);
                     exit(0);
                     }
              default:
                     died = wait(&status);
       }
}


//Create a New Process & Run Both Parent & Child in Parallel
void run_in_background()
{
       int i, count = 0;
       for(i = 0; token[i] != NULL; i++)
              if(strcmp(token[i], "&") == 0)
              {
                     token[i] = NULL;
                     while (token[i+1] != NULL)
                     {
                           token2[count] = token[i+1];
                           token[i+1] = NULL;
                           i++;
                           count++;
                     }
              }
       switch(pid = fork())
       {
              case -1:
                     printf("Something went wrong. Unable to create child :(\n");
                     exit(-1);
              case 0:
                     execvp(token[0], token);
                     printf("Command %s not found\n", token[0]);
                     exit(1);
              default:
                     usleep(10000);
                     exit(0);
       }
}